package com.syqc.monitor.ui.mile

import autodispose2.autoDispose
import com.syqc.base.BaseReportViewModel
import com.syqc.entity.DayMile
import com.syqc.monitor.R
import com.syqc.net.ServiceHelper
import com.syqc.utils.TimeUtil
import io.reactivex.rxjava3.subjects.PublishSubject

/**
 *@Author Jasper
 *@Time   2020/12/8
 *@Desc   todo
 */
class MileViewModel : BaseReportViewModel(
    isThirty = true, isSimple = true
) {
    val mileSub by lazy { PublishSubject.create<DayMile>() }
    override fun getData(carId: String, startTime: String, endTime: String) {
        toastLoading(true)
        ServiceHelper.getRepository().getDayMile(
            carId,
            TimeUtil.instance.formatHm(startTime),
            TimeUtil.instance.formatHm(endTime)
        )
            .autoDispose(this).subscribe({
                toastLoading(false)
                if (it.list.isNullOrEmpty()) {
                    toast(R.string.toast_no_mile_data)
                    return@subscribe
                }
                mileSub.onNext(it)
            }, error)
    }
}
